/*	Copyright 2007 - Xavier Baro (xbaro@cvc.uab.cat)

	This file is part of eapmlib.

    Eapmlib is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or any 
	later version.

    Eapmlib is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __EAPMLEARNER_H__
#define __EAPMLEARNER_H__

#include "EvolutiveLib.h"
#include "EvolLearner.h"
#include "ProbModel.h"

namespace Evolutive {

	//! Defines the evolution strategy
	enum EVOLUTIVELIB_API EVOL_STRATEGY {EVOL_UPDATE,EVOL_ESTIMATE,EVOL_MIXED};
	
	class EVOLUTIVELIB_API CEAPMLearner : public CEvolLearner
	{
		//! Methods
	public:
		//! Default constructor		
		CEAPMLearner(void);

		//! Default destructor
		virtual ~CEAPMLearner(void);		

		//! Sets the probability model
		void SetProbModel(CProbModel *ProbModel);	

		//! Sets the numbero of individuals to update the model
		void SetNumUpdate(int NumIndividuals);

		//! Sets the evolution strategy
		void SetEvolStrategy(EVOL_STRATEGY EvolStrat);

		//! Set the model tolerance
		void SetModelTolerance(double Tolerance);

		//! Set the number of individuals to estimate the model
		void SetNumEstimation(int NumIndividuals);
			
	private:
		//! Check the stop criterias (From the base class)
		virtual bool ApplyStopCriteria(void);

		//! Use the apriory knowledge to build the initial population (From the base class)
		virtual void UseAprioriPopulation(void);

		//! Evolve to the next generation (From the base class)
		virtual void NextGeneration(void);		

		//! Overload the initialization function
		void InitLearner(void);

		//! Model update
		void UpdateModel(void);

		//! Estimate the model
		void EstimateModel(void);
		
							
		//! Attributes
	private:
		//! Pointer to the probability model
		CProbModel *m_ProbModel;	

		//! Number of individuals selected to update the model
		int m_NumUpdatable;

		//! Number of individuals used to estimate the model
		int m_NumEstimation;

		//! Number of cycles between estimation and estimation in mixed mode
		int m_EstimationPeriod;

		//! Evolution strategy.
		EVOL_STRATEGY m_EvolStrat;	

		//! Tolerance to the probability model to decide if it is still or not
		double m_Tolerance;
	};	
}

#endif // __EAPMLEARNER_H__
